package stu.sup.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import stu.sup.entity.Merchants;
import stu.sup.mapper.MerchantsMapper;
import stu.sup.service.IMerchantsService;

/**
 * 本类用来演示：
 *
 * @author:Administrator
 * @data:2020/6/27 0027
 */
@Service
@Transactional
public class MerchantsServiceImpl implements IMerchantsService {

    @Autowired
    private MerchantsMapper merchantsMapper;

    @Override
    public int register(Merchants merchants) {
        return merchantsMapper.insert(merchants);
    }

    @Override
    public int updateByPrimaryKeySelective(Merchants merchants) {
        return merchantsMapper.updateByPrimaryKeySelective(merchants);
    }

    @Override
    public Merchants login(Merchants merchants) {
        merchants = merchantsMapper.selectByUserName(merchants.getMerchantsName());

        if (null != merchants){
            if (merchants.getPassword().equals(merchants.getPassword())){

                BeanUtils.copyProperties(merchants,merchants);
                merchants.setLogin(0);//成功
            }else{
                merchants.setLogin(2);//密码不同
            }
        }else {
            merchants.setLogin(1);//用户不存在
        }
        return merchants;
    }
}
